<?php
namespace app\index\controller;
use think\Controller;
use app\common\model\Setting as SettingModel;

class Base extends Controller {

    public function fetchHtml($html , $data=[]){
        $sys = SettingModel::getItem('sys');
        $htmlData = array_merge([
            'web_title'=> $sys['web']['title'],
            'web_kw'   => $sys['web']['keywords'],
            'web_desc' => $sys['web']['desc'],
            'small_title' => $sys['web']['smalltitle'],
            'small_desc' => $sys['web']['smalldesc'],
            'webhost' => 'http://www.XXXXX.com/'
        ] , $data);
        return $this->fetch($html , $htmlData);
    }
    public function _fetchHtml($html , $data=[]){
        $sys = SettingModel::getItem('sys');
        $htmlData = array_merge([
            'web_title'=> $sys['web']['title'],
            'web_kw'   => $sys['web']['keywords'],
            'web_desc' => $sys['web']['desc'],
            'small_title' => $sys['web']['smalltitle'],
            'small_desc' => $sys['web']['smalldesc'],
            'webhost' => 'http://www.kqba.com/'
        ] , $data);
        return $this->filter(function($content){
            return str_replace(array("\r\n", "\n", "\r","  "),'',$content);
        })->fetch($html , $htmlData);
    }
    /**
     * 返回封装后的 API 数据到客户端
     * @param int $code
     * @param string $msg
     * @param string $url
     * @param array $data
     * @return array
     */
    protected function renderJson($code = 1, $msg = '', $url = '', $data = [])
    {
        return compact('code', 'msg', 'url', 'data');
    }

    /**
     * 返回操作成功json
     * @param string $msg
     * @param string $url
     * @param array $data
     * @return array
     */
    protected function renderSuccess($msg = 'success', $url = '', $data = [])
    {
        return $this->renderJson(1, $msg, $url, $data);
    }

    /**
     * 返回操作失败json
     * @param string $msg
     * @param string $url
     * @param array $data
     * @return array
     */
    protected function renderError($msg = 'error', $url = '', $data = [])
    {
        return $this->renderJson(0, $msg, $url, $data);
    }

}